package longrise.phone.com.bjjt_henan.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.baidu.mapapi.search.route.DrivingRouteLine;

import java.util.List;

import longrise.phone.com.bjjt_henan.R;

/**
 * 百度地图驾车路线
 * Created by Administrator on 2017/4/19.
 */
public class NavLinesAdapter extends BaseAdapter {

    private Context mContext;

    private List<DrivingRouteLine> lists;

    public NavLinesAdapter(Context context) {
        this.mContext = context;
    }

    public void setLists(List lists) {
        this.lists = lists;
        notifyDataSetChanged();
    }

    public List<DrivingRouteLine> getLists() {
        return lists;
    }

    @Override
    public int getCount() {
        return (lists == null) ? 0 : lists.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (null == convertView) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.adapter_navlines_item, null);
            holder.typeTV = (TextView) convertView.findViewById(R.id.navlines_tv_type);
            holder.distanceTV = (TextView) convertView.findViewById(R.id.navlines_tv_distance);
            holder.timeTV = (TextView) convertView.findViewById(R.id.navlines_tv_time);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        DrivingRouteLine data = lists.get(position);
        holder.typeTV.setText("方案" + (position + 1));
        float time = (float) data.getDuration() / 60;
        holder.timeTV.setText(Math.round(time) + "分钟");
        float distance = (float) data.getDistance() / 1000;
        holder.distanceTV.setText(String.format("%.1f", distance) + "公里");
        return convertView;
    }

    private class ViewHolder {
        private TextView typeTV;
        private TextView timeTV;
        private TextView distanceTV;
    }

}
